from PIL import Image,ImageDraw
import sys


def convert(img,radii):
    src_size=img.size
    dst_size=tuple([e*10 for e in src_size])
    radii=radii*10
    circle = Image.new('L',(radii * 2,radii * 2),0)
    draw = ImageDraw.Draw(circle)
    draw.ellipse((0,0,radii * 2,radii * 2),fill=255)
    img = img.convert("RGBA")
    img = img.resize(dst_size,Image.ANTIALIAS)
    w , h = img.size

    alpha = Image.new('L', dst_size, 255)
    alpha.paste(circle.crop((0, 0, radii, radii)), (0, 0))
    alpha.paste(circle.crop((radii, 0, radii * 2, radii)), (w - radii, 0))
    alpha.paste(circle.crop((radii, radii, radii * 2, radii * 2)), (w - radii, h - radii))
    alpha.paste(circle.crop((0, radii, radii, radii * 2)), (0, h - radii))

    img.putalpha(alpha)  # 白色区域透明可见，黑色区域不可见
    img = img.resize(src_size,Image.ANTIALIAS)
    return img
rad = None
out = None
img = Image.open(sys.argv[1])
try:
    rad = int(sys.argv[2])
    out = sys.argv[3]
except:
    if rad is None:
        rad=30
    if out is None:
        out=sys.argv[1]
img = convert(img,rad)
img.save(out,'png')
